package com.stress.testing.instrumentation;

import com.stress.testing.common.matcher.MethodMatcher;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;

public class SimpleMethodElementMatcher implements ElementMatcher<MethodDescription> {
    private MethodMatcher methodMatcher;

    public SimpleMethodElementMatcher(MethodMatcher methodMatcher) {
        this.methodMatcher = methodMatcher;
    }

    @Override
    public boolean matches(MethodDescription target) {
        com.stress.testing.common.matcher.MethodDescription methodDescription = buildMethodDescription(target);
        return this.methodMatcher.match(methodDescription);
    }

    private com.stress.testing.common.matcher.MethodDescription buildMethodDescription(MethodDescription target) {
        String actualName = target.getActualName();

        // TODO: 返回类型和参数解析未处理
        String descriptor = target.getDescriptor();

        com.stress.testing.common.matcher.MethodDescription methodDescription =
                new com.stress.testing.common.matcher.MethodDescription(actualName, descriptor);
        return methodDescription;
    }
}
